﻿using Microsoft.AspNetCore.Mvc;
using ZGL.Api.Entity;
using ZGL.Api.Models.dto;
using ZGL.Api.Models.vo;
using ZGL.Api.Services.User;
using ZGL.Api.Utils;

namespace ZGL.Api.Controllers
{
    /// <summary>
    /// 用户管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        public readonly IUserService UserService;


        public UserController(IUserService userService)
        {
            this.UserService = userService;
        }
        /// <summary>
        /// 用户列表
        /// </summary>
        [HttpPost]
        public IActionResult GetUserList(UserDto userDto)
        {
            Dictionary<string, object> UserList = UserService.getUserList(userDto);

            return new ObjectResult(new R(data: UserList));
        }

        #region 用户新增
        /// <summary>
        /// 用户新增
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult addUser(UserAddDto user)
        {
            UserService.addUser(user);
            return new ObjectResult(new R(data: null));
        }
        #endregion
        #region 修改用户
        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult putUser(UserPutDto user)
        {
            UserService.putUser(user);
            return new ObjectResult(new R(data: null));
        }
        #endregion
        /// <summary>
        /// 获取用户详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult getUser(long id)
        {
            var user = UserService.getUser(id);
            return new ObjectResult(new R(data: user));
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        #region 删除用户
        [HttpDelete]
        public IActionResult delUser(long id)
        {
            var user = UserService.delUser(id);
            return new ObjectResult(new R(data: null, code: 200, message: "请求成功"));
        }
        #endregion
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="logonDto"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult login(LogonDto logonDto)
        {
            Dictionary<string, object> userLoign =UserService.login(logonDto);
            return new ObjectResult(new R(data: userLoign));
        }


    }
}
